package gui;

import com.formdev.flatlaf.FlatDarculaLaf;
import com.formdev.flatlaf.FlatDarkLaf;
import com.formdev.flatlaf.FlatIntelliJLaf;
import com.formdev.flatlaf.FlatLightLaf;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import core.ConcurrentTestUtil;
import plan.*;
import plan.ThreadGroup;

import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.tree.DefaultMutableTreeNode;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.net.URLConnection;
import java.nio.file.Files;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MainGui {

    private JPanel panel1;
    private JTree tree1;
    private JComboBox comboBox1;
    private JTable table1;
    private JButton button1;
    private JButton button2;
    private JPanel panel2;
    private JPanel panel3;
    private JPanel panel4;
    private JTextField textField3;
    private JTextField textField4;
    private JTextField textField5;
    private JTextArea textArea1;
    private JTable table2;
    private JButton button3;
    private JTextField textField1;
    private JTextField textField2;
    private JTextField textField6;
    private JTextField textField7;
    private JTextField textField8;
    private JTextField textField9;
    private JPanel panel5;
    private JProgressBar progressBar1;
    private JPanel panel6;
    private JButton button4;
    private JScrollPane scrollPane1;
    private JMenuBar jMenuBar;
    private JMenu jMenu;
    private JMenuItem jMenu1;
    private JMenuItem jMenu2;
    private JMenuItem jMenu3;
    private JMenuItem jMenu4;

    private TestPlan testPlan = new TestPlan(new TestReport(

    ));

    public MainGui() {
        //添加传输数据
        $$$setupUI$$$();
        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                DefaultTableModel model = (DefaultTableModel) table1.getModel();
                model.addRow(new Vector());
                table1.setModel(model);
            }
        });
        //删除传输数据
        button2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                DefaultTableModel model = (DefaultTableModel) table1.getModel();    //获得表格模型
                int[] selectedRows = table1.getSelectedRows();
                int max = selectedRows[selectedRows.length - 1];
                for (int i = max; i >= selectedRows[0]; i--) {
                    model.removeRow(i);
                }
                table1.setModel(model);
            }
        });
        //点击树操作
        tree1.addTreeSelectionListener(new TreeSelectionListener() {
            @Override
            public void valueChanged(TreeSelectionEvent e) {
                if (e.getSource() == tree1) {
                    DefaultMutableTreeNode tnode = (DefaultMutableTreeNode) tree1.getLastSelectedPathComponent();
                    String str = tnode.toString();
                    CardLayout cl = (CardLayout) (panel2.getLayout());
                    if ("线程数".equals(str)) {
                        cl.show(panel2, "Card1");
                    } else if ("HTTP请求".equals(str)) {
                        cl.show(panel2, "Card2");
                    } else if ("响应数据".equals(str)) {
                        cl.show(panel2, "Card3");
                    } else if ("测试报告".equals(str)) {
                        cl.show(panel2, "Card4");
                    }
                }
            }
        });
        //启动按钮
        button3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                progressBar1.setValue(0);
                //检查是否必要部分全部填写完整
                examine();
                startTest();
            }
        });

        jMenu1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new MainGui().start();
            }
        });

        jMenu2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                saveTo();
            }
        });

        jMenu3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                saveToAnother();
            }
        });

        jMenu4.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    open();
                } catch (IOException ioException) {
                    ioException.printStackTrace();
                }
            }
        });
        button4.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                progressBar1.setValue(0);
            }
        });
    }

    private void createUIComponents() {
        // TODO: place custom component creation code here
        createTree();

        String[] math = {"GET", "POST"};
        comboBox1 = new JComboBox(math);

        progressBar1 = new JProgressBar();
        progressBar1.setMinimum(0);
        progressBar1.setMaximum(100);
        progressBar1.setStringPainted(true);

        createTable();

        createMenu();
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("MainGui");
        frame.setContentPane(new MainGui().panel1);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }

    public void start() {
        FlatLightLaf.install();
        try {
            UIManager.setLookAndFeel(new FlatIntelliJLaf());
        } catch (Exception ex) {
            System.err.println("Failed to initialize LaF");
        }
        UIManager.put("Table.showHorizontalLines", true);
        UIManager.put("Table.showVerticalLines", true);
        UIManager.put("Table.gridColor", new Color(175, 175, 175));
        UIManager.put("TableHeader.separatorColor", new Color(175, 175, 175));
        UIManager.put("TableHeader.bottomSeparatorColor", new Color(175, 175, 175));

        JFrame frame = new JFrame(testPlan.getName());
        frame.setContentPane(new MainGui().panel1);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }

    public TestPlan getTestPlan() {
        return this.testPlan;
    }

    private void createTree() {
        // 创建根节点
        DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("TestPlan");

        // 创建二级节点
        DefaultMutableTreeNode gdNode = new DefaultMutableTreeNode("线程数");
        DefaultMutableTreeNode fjNode = new DefaultMutableTreeNode("HTTP请求");
        DefaultMutableTreeNode shNode = new DefaultMutableTreeNode("响应数据");
        DefaultMutableTreeNode twNode = new DefaultMutableTreeNode("测试报告");

        // 把二级节点作为子节点添加到根节点
        rootNode.add(gdNode);
        rootNode.add(fjNode);
        rootNode.add(shNode);
        rootNode.add(twNode);


        // 使用根节点创建树组件
        tree1 = new JTree(rootNode);
    }

    private void createTable() {
        String[] nameAndValue = {"名称", "值"};
        table1 = new JTable();
        DefaultTableModel model = new DefaultTableModel(nameAndValue, 0);
        table1.setModel(model);
        table1.getTableHeader().setReorderingAllowed(false);

        String[] nameAndValue2 = {"名称", "请求数", "平均响应时间", "中位数", "90%Line", "95%Line", "99%Line", "最小响应时间",
                "最大响应时间", "错误数", "吞吐量"};
        table2 = new JTable();
        DefaultTableModel model2 = new DefaultTableModel(nameAndValue2, 0);
        table2.setModel(model2);
        table2.getTableHeader().setReorderingAllowed(false);
        table2.setEnabled(false);
    }

    private void createMenu() {
        jMenuBar = new JMenuBar();  //定义菜单
        jMenu = new JMenu("文件");  //  创建菜单
        jMenu1 = new JMenuItem("新建");  //  菜单中的菜单
        jMenu2 = new JMenuItem("保存");
        jMenu3 = new JMenuItem("另存为");
        jMenu4 = new JMenuItem("打开");

        jMenu.add(jMenu1);
        jMenu.addSeparator();
        jMenu.add(jMenu2);
        jMenu.addSeparator();
        jMenu.add(jMenu3);
        jMenu.addSeparator();
        jMenu.add(jMenu4);

        jMenuBar.add(jMenu);

        panel5 = new JPanel();
        panel5.add(jMenuBar);
    }

    private void examine() {
        String threadNum = textField2.getText();
        String loop = textField6.getText();
        String agreement = textField8.getText();
        String servers = textField9.getText();
        if ("".equals(threadNum)) {
            JOptionPane.showMessageDialog(null, "请设置线程数", "错误", JOptionPane.WARNING_MESSAGE);
        } else if (!threadNum.chars().allMatch(Character::isDigit)) {
            JOptionPane.showMessageDialog(null, "请输入数字", "错误", JOptionPane.WARNING_MESSAGE);
        } else if ("".equals(loop)) {
            JOptionPane.showMessageDialog(null, "请设置循环数", "错误", JOptionPane.WARNING_MESSAGE);
        } else if (!loop.chars().allMatch(Character::isDigit)) {
            JOptionPane.showMessageDialog(null, "请输入数字", "错误", JOptionPane.WARNING_MESSAGE);
        } else if ("".equals(agreement)) {
            JOptionPane.showMessageDialog(null, "请设置传输协议", "错误", JOptionPane.WARNING_MESSAGE);
        } else if ("".equals(servers)) {
            JOptionPane.showMessageDialog(null, "请设置服务器或IP", "错误", JOptionPane.WARNING_MESSAGE);
        }
    }

    private void startTest() {
        String threadName = textField1.getText();
        String threadNum = textField2.getText();
        String loop = textField6.getText();
        String httpName = textField7.getText();
        String agreement = textField8.getText();
        String servers = textField9.getText();
        String port = textField3.getText();
        String math = comboBox1.getSelectedItem().toString();
        String path = textField4.getText();
        String encoding = textField5.getText();
        Map<String, String> nameAndValue = new HashMap<>();
        int raw = table1.getRowCount();
        for (int i = 0; i < raw && raw > 0; i++) {
            nameAndValue.put(table1.getValueAt(i, 0) + "", table1.getValueAt(i, 1) + "");
        }
        String url = "";
        System.out.println(port);
        if (!port.isEmpty()) {
            url = agreement + "://" + servers + ":" + port + path;
        } else {
            url = agreement + "://" + servers + path;
        }
        String param = "";
        int nameSize = nameAndValue.size();
        Iterator it = nameAndValue.keySet().iterator();
        while (it.hasNext()) {
            Object key = it.next();
            Object value = nameAndValue.get(key);
            param += key + "=" + value + "&";
        }
        if (nameSize > 0) {
            param = param.substring(0, param.length() - 1);
        }

        ThreadGroup threadGroup = new ThreadGroup(threadName, Integer.parseInt(threadNum),
                Integer.parseInt(loop));
        HttpRequest httpRequest = new HttpRequest(agreement, servers, port, url, math, path, encoding, param, nameAndValue);
        Result result = new Result();

        TestReport testReport = testPlan.getTestReport();

        testPlan.setThreadGroup(threadGroup);
        testPlan.setHttpRequest(httpRequest);
        testPlan.setResult(result);


        try {
            ConcurrentTestUtil.doRequest(testPlan, progressBar1);
        } catch (Exception exception) {
            exception.printStackTrace();
        }

        textArea1.setText(result.getRes());
        DefaultTableModel model = (DefaultTableModel) table2.getModel();
        int n = testReport.getMin().size() - 1;
        testReport.setName(threadGroup.getThreadName());
        testReport.setSamples(threadGroup.getSamples());
        Vector vector = new Vector();
        vector.add(threadGroup.getThreadName());
        vector.add(threadGroup.getSamples());
        vector.add(testReport.getAverage().get(n));
        vector.add(testReport.getMedia().get(n));
        vector.add(testReport.getLine90().get(n));
        vector.add(testReport.getLine95().get(n));
        vector.add(testReport.getLine99().get(n));
        vector.add(testReport.getMin().get(n));
        vector.add(testReport.getMax().get(n));
        vector.add(testReport.getError().get(n));
        vector.add(testReport.getThroughput().get(n));
        model.addRow(vector);
        table2.setModel(model);
    }

    private void save() {
        String threadName = textField1.getText();
        String threadNum = textField2.getText();
        String loop = textField6.getText();
        String httpName = textField7.getText();
        String agreement = textField8.getText();
        String servers = textField9.getText();
        String port = textField3.getText();
        String math = comboBox1.getSelectedItem().toString();
        String path = textField4.getText();
        String encoding = textField5.getText();
        String res = textArea1.getText();
        Map<String, String> nameAndValue = new HashMap<>();
        int raw = table1.getRowCount();
        for (int i = 0; i < raw && raw > 0; i++) {
            nameAndValue.put(table1.getValueAt(i, 0).toString(), table1.getValueAt(i, 1).toString());
        }
        String url = agreement + "://" + servers + ":" + port + path;
        String param = "";
        int nameSize = nameAndValue.size();
        Iterator it = nameAndValue.keySet().iterator();
        while (it.hasNext()) {
            Object key = it.next();
            Object value = nameAndValue.get(key);
            param += key + "=" + value + "&";
        }
        if (nameSize > 0) {
            param = param.substring(0, param.length() - 1);
        }
        int raw2 = table2.getRowCount();

        ArrayList<String> name = new ArrayList<>(); // Request Name
        ArrayList<Integer> samples = new ArrayList<>(); //请求数
        ArrayList<Double> average = new ArrayList<>(); //平均响应时间
        ArrayList<Long> media = new ArrayList<>(); //中位数，50%用户响应时间
        ArrayList<Long> line90 = new ArrayList<>(); //90%用户响应时间
        ArrayList<Long> line95 = new ArrayList<>();
        ArrayList<Long> line99 = new ArrayList<>();
        ArrayList<Long> min = new ArrayList<>(); //最小响应时间
        ArrayList<Long> max = new ArrayList<>(); //最大响应时间
        ArrayList<Float> error = new ArrayList<>(); //错误页面
        ArrayList<Double> throughput = new ArrayList<>(); //吞吐量
        for (int i = 0; i < raw2 && raw2 > 0; i++) {
            name.add(table2.getValueAt(i, 0).toString());
            samples.add((int) table2.getValueAt(i, 1));
            average.add((double) table2.getValueAt(i, 2));
            media.add((Long) table2.getValueAt(i, 3));
            line90.add((Long) table2.getValueAt(i, 4));
            line95.add((Long) table2.getValueAt(i, 5));
            line99.add((Long) table2.getValueAt(i, 6));
            min.add((Long) table2.getValueAt(i, 7));
            max.add((Long) table2.getValueAt(i, 8));
            error.add((float) table2.getValueAt(i, 9));
            throughput.add((double) table2.getValueAt(i, 10));
        }

        ThreadGroup threadGroup = new ThreadGroup(threadName, Integer.parseInt(threadNum),
                Integer.parseInt(loop));
        HttpRequest httpRequest = new HttpRequest(agreement, servers, port, url, math, path, encoding, param, nameAndValue);
        Result result = new Result(res);
        TestReport testReport = new TestReport(name, samples, average, media, line90, line95, line99,
                min, max, error, throughput);

        testPlan.setThreadGroup(threadGroup);
        testPlan.setHttpRequest(httpRequest);
        testPlan.setResult(result);
        testPlan.setTestReport(testReport);
    }

    private void saveTo() {
        save();
        String filePath = testPlan.getName() + ".dat";
        writeObjectToFile(testPlan, filePath);
    }

    private void saveToAnother() {
        save();
        Object temp = "";
        File directory = new File("");//参数为空
        String courseFile = null;
        try {
            courseFile = directory.getCanonicalPath();
        } catch (IOException e) {
            e.printStackTrace();
        }
        JFileChooser fc = new JFileChooser(courseFile);
        // 设置打开文件选择框后默认输入的文件名
        fc.setSelectedFile(new File(testPlan.getName() + ".dat"));
        int val = fc.showSaveDialog(null);    //文件打开对话框
        String filePath = "";
        if (val == fc.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            filePath = file.getAbsolutePath();
        }

        writeObjectToFile(testPlan, filePath);
    }

    private void writeObjectToFile(TestPlan obj, String path) {
        File file = new File(path);
        FileOutputStream out;
        try {
            out = new FileOutputStream(file);
            ObjectOutputStream objOut = new ObjectOutputStream(out);
            objOut.writeObject(obj);
            objOut.flush();
            objOut.close();
            System.out.println("write object success!");
        } catch (IOException e) {
            System.out.println("write object failed");
            e.printStackTrace();
        }
    }

    private void open() throws IOException {
        Object temp = "";
        File directory = new File("");//参数为空
        String courseFile = null;
        try {
            courseFile = directory.getCanonicalPath();
        } catch (IOException e) {
            e.printStackTrace();
        }
        JFileChooser fc = new JFileChooser(courseFile);
        int val = fc.showOpenDialog(null);    //文件打开对话框
        File file = new File("");
        if (val == fc.APPROVE_OPTION) {
            file = fc.getSelectedFile();
        }
        if ("application/x-java-serialized-object".equals(file.toURL().openConnection().getContentType())) {
        } else {
            JOptionPane.showMessageDialog(null, "请选择正确测试计划文件", "错误", JOptionPane.WARNING_MESSAGE);
        }
        FileInputStream in;
        try {
            in = new FileInputStream(file);
            ObjectInputStream objIn = new ObjectInputStream(in);
            temp = objIn.readObject();
            objIn.close();
            System.out.println("read object success!");
        } catch (IOException e) {
            System.out.println("read object failed");
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        TestPlan testPlan = (TestPlan) temp;

        HttpRequest httpRequest = testPlan.getHttpRequest();
        Result result = testPlan.getResult();
        TestReport testReport = testPlan.getTestReport();
        ThreadGroup threadGroup = testPlan.getThreadGroup();

        textField1.setText(threadGroup.getThreadName());
        textField2.setText(threadGroup.getThreadNum() + "");
        textField6.setText(threadGroup.getLoop() + "");

        textField8.setText(httpRequest.getHtp());
        textField9.setText(httpRequest.getIp());
        textField3.setText(httpRequest.getPort());
        if ("GET".equals(httpRequest.getFuc())) {
            comboBox1.setSelectedIndex(0);
        } else {
            comboBox1.setSelectedIndex(1);
        }
        textField4.setText(httpRequest.getPath());
        textField5.setText(httpRequest.getEncoding());
        Map<String, String> nameAndValue = httpRequest.getNameAndValue();
        Iterator it = nameAndValue.keySet().iterator();
        while (it.hasNext()) {
            DefaultTableModel model = (DefaultTableModel) table1.getModel();
            Vector vector = new Vector();
            Object key = it.next();
            Object value = nameAndValue.get(key);
            vector.add(key);
            vector.add(value);
            model.addRow(vector);
            table1.setModel(model);
        }

        textArea1.setText(result.getRes());

        int n = testReport.getAverage().size();
        for (int i = 0; i < n; i++) {
            DefaultTableModel model = (DefaultTableModel) table2.getModel();
            Vector vector = new Vector();
            vector.add(testReport.getName().get(i));
            vector.add(testReport.getSamples().get(i));
            vector.add(testReport.getAverage().get(i));
            vector.add(testReport.getMedia().get(i));
            vector.add(testReport.getLine90().get(i));
            vector.add(testReport.getLine95().get(i));
            vector.add(testReport.getLine99().get(i));
            vector.add(testReport.getMin().get(i));
            vector.add(testReport.getMax().get(i));
            vector.add(testReport.getError().get(i));
            vector.add(testReport.getThroughput().get(i));
            model.addRow(vector);
            table2.setModel(model);
        }

        System.out.println(testPlan.getThreadGroup().getThreadNum());
    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        createUIComponents();
        panel1 = new JPanel();
        panel1.setLayout(new GridLayoutManager(3, 3, new Insets(0, 0, 0, 0), -1, -1));
        panel1.setMinimumSize(new Dimension(150, 64));
        panel2 = new JPanel();
        panel2.setLayout(new CardLayout(0, 0));
        panel1.add(panel2, new GridConstraints(1, 2, 1, 1, GridConstraints.ANCHOR_NORTH, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        panel3 = new JPanel();
        panel3.setLayout(new GridLayoutManager(4, 3, new Insets(0, 0, 0, 0), -1, -1));
        panel2.add(panel3, "Card1");
        panel3.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), null, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        final JLabel label1 = new JLabel();
        label1.setText("线程数");
        panel3.add(label1, new GridConstraints(0, 0, 1, 3, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(-1, 10), null, 0, false));
        final JPanel panel7 = new JPanel();
        panel7.setLayout(new FlowLayout(FlowLayout.LEADING, 5, 5));
        panel3.add(panel7, new GridConstraints(1, 0, 1, 3, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(600, 70), null, 0, false));
        panel7.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), null, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        final JLabel label2 = new JLabel();
        label2.setText("名称：");
        panel7.add(label2);
        textField1 = new JTextField();
        textField1.setColumns(45);
        textField1.setEnabled(true);
        panel7.add(textField1);
        final JLabel label3 = new JLabel();
        label3.setText("注释：");
        panel7.add(label3);
        final JTextField textField10 = new JTextField();
        textField10.setColumns(45);
        panel7.add(textField10);
        final JPanel panel8 = new JPanel();
        panel8.setLayout(new FlowLayout(FlowLayout.LEADING, 5, 5));
        panel3.add(panel8, new GridConstraints(2, 0, 1, 3, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(600, 70), null, 0, false));
        panel8.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), null, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        final JLabel label4 = new JLabel();
        label4.setText("线程数：");
        panel8.add(label4);
        textField2 = new JTextField();
        textField2.setColumns(45);
        panel8.add(textField2);
        final JLabel label5 = new JLabel();
        label5.setText("循环次数");
        panel8.add(label5);
        textField6 = new JTextField();
        textField6.setColumns(45);
        panel8.add(textField6);
        final JPanel panel9 = new JPanel();
        panel9.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
        panel3.add(panel9, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(-1, 300), null, 0, false));
        panel4 = new JPanel();
        panel4.setLayout(new GridLayoutManager(4, 1, new Insets(0, 0, 0, 0), -1, -1));
        panel2.add(panel4, "Card2");
        panel4.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), null, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        final JLabel label6 = new JLabel();
        label6.setText("HTTP请求");
        panel4.add(label6, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(-1, 10), null, 0, false));
        final JPanel panel10 = new JPanel();
        panel10.setLayout(new FlowLayout(FlowLayout.LEADING, 5, 5));
        panel4.add(panel10, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(600, 70), null, 0, false));
        panel10.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), null, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        final JLabel label7 = new JLabel();
        label7.setText("名称：");
        panel10.add(label7);
        textField7 = new JTextField();
        textField7.setColumns(45);
        panel10.add(textField7);
        final JLabel label8 = new JLabel();
        label8.setText("注释：");
        panel10.add(label8);
        final JTextField textField11 = new JTextField();
        textField11.setColumns(45);
        panel10.add(textField11);
        final JPanel panel11 = new JPanel();
        panel11.setLayout(new FlowLayout(FlowLayout.LEADING, 5, 5));
        panel4.add(panel11, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(600, 70), null, 0, false));
        panel11.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Web服务器", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        final JLabel label9 = new JLabel();
        label9.setText("协议：");
        panel11.add(label9);
        textField8 = new JTextField();
        textField8.setColumns(5);
        panel11.add(textField8);
        final JLabel label10 = new JLabel();
        label10.setText("服务器名称或ip");
        panel11.add(label10);
        textField9 = new JTextField();
        textField9.setColumns(15);
        panel11.add(textField9);
        final JLabel label11 = new JLabel();
        label11.setText("端口号");
        panel11.add(label11);
        textField3 = new JTextField();
        textField3.setColumns(5);
        panel11.add(textField3);
        final JPanel panel12 = new JPanel();
        panel12.setLayout(new FlowLayout(FlowLayout.LEADING, 5, 5));
        panel4.add(panel12, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(600, 350), null, 0, false));
        panel12.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "HTTP请求", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        final JLabel label12 = new JLabel();
        label12.setText("方法：");
        panel12.add(label12);
        panel12.add(comboBox1);
        final JLabel label13 = new JLabel();
        label13.setText("路径：");
        panel12.add(label13);
        textField4 = new JTextField();
        textField4.setColumns(20);
        panel12.add(textField4);
        final JLabel label14 = new JLabel();
        label14.setText("编码格式：");
        panel12.add(label14);
        textField5 = new JTextField();
        textField5.setColumns(5);
        panel12.add(textField5);
        final JPanel panel13 = new JPanel();
        panel13.setLayout(new GridLayoutManager(3, 1, new Insets(0, 0, 0, 0), -1, -1));
        panel12.add(panel13);
        panel13.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), null, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        final JLabel label15 = new JLabel();
        label15.setText("发送的参数");
        panel13.add(label15, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        final JScrollPane scrollPane2 = new JScrollPane();
        scrollPane2.setForeground(new Color(-5263441));
        panel13.add(scrollPane2, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, new Dimension(560, 200), null, 0, false));
        scrollPane2.setViewportView(table1);
        final JPanel panel14 = new JPanel();
        panel14.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
        panel13.add(panel14, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        button1 = new JButton();
        button1.setText("添加");
        panel14.add(button1);
        button2 = new JButton();
        button2.setText("删除");
        panel14.add(button2);
        final JPanel panel15 = new JPanel();
        panel15.setLayout(new GridLayoutManager(3, 2, new Insets(0, 0, 0, 0), -1, -1));
        panel2.add(panel15, "Card3");
        panel15.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), null, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        final JLabel label16 = new JLabel();
        label16.setText("响应结果");
        panel15.add(label16, new GridConstraints(0, 0, 2, 2, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(-1, 10), null, 0, false));
        final JPanel panel16 = new JPanel();
        panel16.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
        panel15.add(panel16, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(560, 350), null, 0, false));
        final JScrollPane scrollPane3 = new JScrollPane();
        panel16.add(scrollPane3, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
        textArea1 = new JTextArea();
        scrollPane3.setViewportView(textArea1);
        final JPanel panel17 = new JPanel();
        panel17.setLayout(new GridLayoutManager(2, 2, new Insets(0, 0, 0, 0), -1, -1));
        panel15.add(panel17, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(-1, 100), null, 0, false));
        final Spacer spacer1 = new Spacer();
        panel17.add(spacer1, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
        final Spacer spacer2 = new Spacer();
        panel17.add(spacer2, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
        final JPanel panel18 = new JPanel();
        panel18.setLayout(new GridLayoutManager(2, 2, new Insets(0, 0, 0, 0), -1, -1));
        panel2.add(panel18, "Card4");
        panel18.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), null, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        final JLabel label17 = new JLabel();
        label17.setText("测试结果");
        panel18.add(label17, new GridConstraints(0, 0, 2, 2, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(-1, 10), null, 0, false));
        final JPanel panel19 = new JPanel();
        panel19.setLayout(new GridLayoutManager(3, 1, new Insets(0, 0, 0, 0), -1, -1));
        panel18.add(panel19, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(520, 300), null, 0, false));
        final JScrollPane scrollPane4 = new JScrollPane();
        panel19.add(scrollPane4, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(600, 300), null, 0, false));
        table2.setPreferredScrollableViewportSize(new Dimension(450, 550));
        scrollPane4.setViewportView(table2);
        final JPanel panel20 = new JPanel();
        panel20.setLayout(new FlowLayout(FlowLayout.LEADING, 5, 5));
        panel19.add(panel20, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(540, 70), null, 0, false));
        panel20.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), null, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        final JLabel label18 = new JLabel();
        label18.setText("名称：");
        panel20.add(label18);
        final JTextField textField12 = new JTextField();
        textField12.setColumns(40);
        textField12.setText("测试结果");
        panel20.add(textField12);
        final JLabel label19 = new JLabel();
        label19.setText("注释：");
        panel20.add(label19);
        final JTextField textField13 = new JTextField();
        textField13.setColumns(40);
        panel20.add(textField13);
        final JPanel panel21 = new JPanel();
        panel21.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
        panel19.add(panel21, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_NORTH, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(-1, 80), null, 0, false));
        final JPanel panel22 = new JPanel();
        panel22.setLayout(new GridLayoutManager(1, 3, new Insets(0, 0, 0, 5), -1, -1));
        panel1.add(panel22, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        button3 = new JButton();
        button3.setHorizontalAlignment(0);
        button3.setHorizontalTextPosition(11);
        button3.setText("Start");
        panel22.add(button3, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        button4 = new JButton();
        button4.setText("初始化");
        panel22.add(button4, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        panel22.add(progressBar1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        panel1.add(panel5, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        final JPanel panel23 = new JPanel();
        panel23.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
        panel1.add(panel23, new GridConstraints(2, 0, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        panel6 = new JPanel();
        panel6.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
        panel1.add(panel6, new GridConstraints(1, 0, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        panel6.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), null, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        panel6.add(tree1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_WANT_GROW, null, new Dimension(150, 50), null, 0, false));
    }

    /**
     * @noinspection ALL
     */
    public JComponent $$$getRootComponent$$$() {
        return panel1;
    }

}
